efform_onload = function ()
{	
	$("#ef_region_detail").hide();
}; 

button_query_onclick = function () 
{   	
	efgrid.submitInqu( "ef_grid_r", "ZM","ZMCG40","query");
}

button_insert_onclick = function (){
	if (isSelected("ef_grid_r") == 0)return; 
	efgrid.submitForm( "ef_grid_r", "ZM","ZMCG40","insert",true);
}

button_update_onclick = function (){ 
	var grid=isSelected("ef_grid_r");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="0")
		{
			EFAlert("只能对处理中的记录进行修改！"); return;
		}
	}
	efgrid.submitForm( "ef_grid_r", "ZM","ZMCG40","update",true);
}

button_delete_onclick = function (){
	var grid=isSelected("ef_grid_r");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="0")
		{
			EFAlert("只能对处理中的记录进行删除！"); return;
		}
	}
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_r", "ZM","ZMCG40","delete",true);
	});
}

button_resolve_onclick = function (){ 
	var grid=isSelected("ef_grid_r");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="0")
		{
			EFAlert("只能对处理中的记录进行解决！"); return;
		}
	}
	EFConfirm('你确认要解决吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_r", "ZM", "ZMCG40", "resolve",true);
	});
}


efgrid_onRowClicked = function( grid_id, row_index ){
	if(grid_id == "ef_grid_r"){
		var grid = efgrid.getGridObject(grid_id);
		var fdChangeId = grid.getCellValueByColumnName(row_index, "fdKeyId");
		var fdEditDate = grid.getCellValueByColumnName(row_index, "fdEditDate");
		var fdStatus = grid.getCellValueByColumnName(row_index, "fdStatus");
		
		//隐藏/显示从表按钮
		if(fdStatus != '0')
			hideAndShowSubButtons(false);
		else
			hideAndShowSubButtons(true);
		
		var info = new EiInfo();
		info.set("fdChangeId", fdChangeId);
		info.set("fdCurrentDate", fdEditDate);
		$('#fdChangeId').val(fdChangeId);
		$('#fdCurrentDate').val(fdEditDate);
		EiCommunicator.send("ZMCG4001", "query", info, ajax_callback);  
	}
}

var ajax_callback= {
	onSuccess: function(eiInfo) { 
		 efwindow.hide();
		 var grid = efgrid.getGridObject("ef_grid_d");
		 grid.refresh(eiInfo);
		 $('#ef_region_detail').show();
	},
	onFail:function(eMsg)
	{
		EFAlert("失败，原因："+eMsg, "警告"); 
	}
}

//新增、修改、删除后的执行方法
efgrid_onAjaxSubmitSuccess = function(gridId, service_name, method_name, eiInfo) {
	if(gridId == "ef_grid_r") {
		var grid = efgrid.getGridObject(gridId);
		grid.refresh( eiInfo );
		clearRegion("ef_grid_d");
		$("#ef_region_detail").hide();
	}
	else {
		if (eiInfo.status != -1) {
			var grid = efgrid.getGridObject("ef_grid_d");
			grid.refresh( eiInfo );
		}
		else
		{
			submitCallBackEiMsg = eiInfo.msg;
		}
	}
};

/********************************************************************************
 ***********************************从表操作**************************************** 
 ********************************************************************************/
button_insertdetail_onclick = function (){
	if (isSelected("ef_grid_d") == 0)return;
	efgrid.submitForm("ef_grid_d", "ZM", "ZMCG4001", "insert", true); 
}

//从表修改按钮
button_updatedetail_onclick = function (){
	if (isSelected("ef_grid_d") == 0)return; 
	efgrid.submitForm("ef_grid_d", "ZM", "ZMCG4001", "update", true);
}

//从表删除按钮
button_deletedetail_onclick = function (){
	var grid = isSelected("ef_grid_d");
	if (grid == 0) return;  
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r){
			efgrid.submitForm("ef_grid_d", "ZM", "ZMCG4001", "delete", true);
		}
	}); 
} 

var hideAndShowSubButtons=function(status)
{
	if(!status)
	{
		efbutton.setButtonStatus("insertdetail", false);
		efbutton.setButtonStatus("updatedetail", false);
		efbutton.setButtonStatus("deletedetail", false);
	}else
	{
		efbutton.setButtonStatus("insertdetail", true);
		efbutton.setButtonStatus("updatedetail", true);
		efbutton.setButtonStatus("deletedetail", true);
	}
}

/**----------------------------从这里往下的方法都是附件操作相关方法------------------
 */

//点击了新增行之后，给一些默认数据
//主表新增时，给默认数据
efgrid_afterAddNewRow = function(grid_id){ 
	var grid = efgrid.getGridObject(grid_id);
	var rows = grid.getCheckedRows();
	if(grid_id=="ef_grid_r")
	{	    
		for(var i = 0 ; i < rows.length;i++){
			grid.getBlockData().setCell(rows[i], "fdStatus", "0");
			grid.getBlockData().setCell(rows[i], "fdEditDate", getCurrentDate());
		}
	}
	for (var i = 0; i < rows.length; i++) {
		grid.getBlockData().setCell(rows[i], "fdKeyId", "");
	}
}

button_upload_onclick=function(){
	var grid=isSelected("ef_grid_r");
	if (grid == 0)return;
	var row_index=grid.getCheckedRowCount();
	var row=grid.getCheckedRows();
	if(row_index>1){
		EFAlert("只能选中一条项目信息后上传！");
		return;
	}
	var docId=grid.getCellValueByColumnName(row,"fdDocId");
	if(!isAvailable(docId)) {
		EFAlert("未指定文档号！", "系统警告");
		return false;
	}
	var url = "DispatchAction.do?efFormEname=EUAF3501";
		url = url + "&inqu_status-0-code=zm.cp";
	
	if(grid.getCellValueByColumnName(row,"fdStatus")!="0")
	{
		url = url + "&editFlag=0";
	}else{
		url = url + "&editFlag=1";
	}
	url = url + "&inqu_status-0-docId="+docId+"&time=" + new Date().getTime();
	
	EFColorbox({href:url,title:"附件管理",width:"80%", height:"80%", iframe:true});
}